using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace ResourceBlender_Express {
    /// <summary>
    /// A resource used by one or more elements
    /// </summary>
    public class RBResource : INotifyPropertyChanged {
        private int id;
        private string comment;
        private ObservableSortedDictionary<string, RBTranslation> translations;

        /// <summary>
        /// Gets or sets resource ID.
        /// </summary>
        /// <value>The ID.</value>
        public int ID {
            get { return id; }
            set {
                id = value;
                OnPropertyChanged("ID");
            }
        }

        /// <summary>
        /// Gets or sets the comment for this resource.
        /// </summary>
        /// <value>The comment.</value>
        public string Comment {
            get { return comment; }
            set {
                comment = value;
                OnPropertyChanged("Comment");
            }
        }

        /// <summary>
        /// Gets or sets a dictionary of translations for the resource sorted by the language's English name. In the format <code, translation>
        /// </summary>
        /// <value>A dictionary of the translations available.</value>
        public ObservableSortedDictionary<string, RBTranslation> Translations {
            get { return translations; }
            set {
                translations = value;
                OnPropertyChanged("Translations");
            }
        }

        /// <summary>
        /// Initializes a new <see cref="RBResource"/>.
        /// </summary>
        public RBResource() {
            id = -1;
            comment = string.Empty;
            translations = new ObservableSortedDictionary<string, RBTranslation>(new Comparers.LanguageNameDictionaryComparer(Comparers.LanguageNameDictionaryComparer.CompareMode.Keys));
        }

        /// <summary>
        /// Initializes a new <see cref="RBResource"/>.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="comment">The comment.</param>
        public RBResource(int id, string comment)
            : this() {
            this.id = id;
            this.comment = comment;
        }

        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged(string strPropertyName) {
            if(PropertyChanged != null) {
                PropertyChanged(this, new PropertyChangedEventArgs(strPropertyName));
            }
        }
    }
}
